import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
} from 'typeorm';

export enum PaymentStatus {
  PENDING = 'pending',
  SUCCESS = 'success',
  FAILED = 'failed',
  CANCELLED = 'cancelled',
}

@Entity('payment_orders')
export class PaymentOrder {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  id: number;

  @Column({ type: 'varchar', length: 32, unique: true, comment: '订单号' })
  orderNo: string;

  @Column({ type: 'bigint', nullable: true, comment: '用户ID' })
  userId?: number;

  @Column({ type: 'decimal', precision: 10, scale: 2, comment: '订单金额' })
  amount: number;

  @Column({ 
    type: 'enum', 
    enum: PaymentStatus, 
    default: PaymentStatus.PENDING, 
    comment: '支付状态' 
  })
  status: PaymentStatus;

  @Column({ type: 'varchar', length: 50, comment: '支付方式' })
  paymentMethod: string;

  @Column({ type: 'varchar', length: 100, nullable: true, comment: '第三方订单号' })
  thirdPartyOrderNo?: string;

  @Column({ type: 'text', nullable: true, comment: '支付回调数据' })
  callbackData?: string;

  @Column({ type: 'varchar', length: 255, nullable: true, comment: '订单描述' })
  description?: string;

  @Column({ type: 'datetime', nullable: true, comment: '支付完成时间' })
  completeTime?: Date;

  @Column({ type: 'varchar', length: 255, nullable: true, comment: '失败原因' })
  failReason?: string;

  @Column({ type: 'varchar', length: 45, nullable: true, comment: '客户端IP' })
  clientIp?: string;

  @CreateDateColumn({ comment: '创建时间' })
  createTime: Date;

  @UpdateDateColumn({ comment: '更新时间' })
  updateTime: Date;
}